package game.macro;

#if macro
import haxe.macro.Context;
import haxe.macro.Expr.Field;

/**
 * 自动为origin开头的属性追加一个新的_origin属性，用于后续计算使用
 */
class FrameDataMacro {
	macro public static function build():Array<Field> {
		var array = Context.getBuildFields();
		var copy = array.copy();
		for (item in array) {
			if (item.name.indexOf("origin") != -1) {
				copy.push({
					name: "_" + item.name,
					access: [APrivate],
					kind: item.kind,
					pos: Context.currentPos()
				});
				var name = StringTools.replace(item.name, "origin", "");
				name = name.charAt(0).toLowerCase() + name.substr(1);
				copy.push({
					name: name,
					access: [APublic],
					kind: item.kind,
					pos: Context.currentPos()
				});
			}
		}
		return copy;
	}
}
#end
